home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / progs / demo / X11 / animation / r_movie.hs < prev    next >
Encoding:
Text File  |  1994-09-27  |  3.7 KB  |  115 lines  |  [TEXT/YHS2]

  1. {-*********************************************************************
  2.   MODULE R_MOVIE
  3.  
  4.     This module contains necessary functions for editing Movies. There
  5.   are several that give information on a Movie, such as the heights or
  6.   wirdths of its Pics. The others all deal with the various ways of
  7.   combining various Movies into one Movie, a vital set of functions.
  8.  
  9. *********************************************************************-}
  10.  
  11. module R_Movie (ht, wid, orig,
  12.                 above, rABOVE, beside, rBESIDE,rBESIDE2, over, rOVER,
  13.                 overlay, rOVERLAY, pUT,
  14.                 uncurry, curry
  15.                 ) where
  16.  
  17. import R_Ptypes
  18. import R_Constants
  19. import R_Utility
  20. import R_Picture
  21.  
  22.   -- takes a function and a list and returns a new list of element operated
  23.   -- on by the function.
  24. promote:: (a->b)->[a]->[b]
  25. promote f []     = []
  26. promote f [p]    = f p:promote f [p]
  27. promote f (p:ps) = f p:promote f ps
  28.  
  29.   -- promote1 takes a function that analyzes a Pic, and then applies it
  30.   -- to analyse a movie, returning a list.
  31. promote1:: (Pic->a) -> Movie -> [a]
  32. promote1 f ps = [f p | p <- ps]
  33.  
  34.   -- ht takes a Movie and returns a list of the heights of the Pics
  35. ht :: Movie -> [Int]
  36. ht   = promote1 ht_Pic
  37.  
  38.   -- wid takes a Movie and returns a list of the widths of the Pics
  39. wid :: Movie -> [Int]
  40. wid  = promote1 wid_Pic
  41.  
  42.   -- orig takes a Movie and returns a list of vectors that are the
  43.   -- origins of the Pics
  44. orig:: Movie -> [Vec]
  45. orig = promote1 orig_Pic
  46.  
  47.   -- promote2 takes a function accepting an element and a Pic, and
  48.   -- applies the function to the Movie and list, producing a new Movie
  49. promote2:: (a->Pic->Pic) -> [a] -> Movie -> Movie
  50. promote2 f ps qs = [f p q | (p,q) <- zip2 ps qs]
  51.  
  52.   -- takes two Movies and puts them above one another
  53. above:: Movie -> Movie -> Movie
  54. above = promote2 above_Pic
  55.  
  56.   -- takes a list of Movies and puts them all above one another
  57. rABOVE:: [Movie] -> Movie
  58. rABOVE = reduce above
  59.  
  60.   -- takes two Movies and puts them beside one another
  61. beside:: Movie -> Movie -> Movie
  62. beside = promote2 beside_Pic
  63.  
  64.   -- takes a list of Movies and puts them all beside one another
  65. rBESIDE:: [Movie] -> Movie
  66. rBESIDE = reduce beside
  67.  
  68.   -- same as beside, but with absolute coordinates.
  69. beside2:: Movie -> Movie -> Movie
  70. beside2 = promote2 beside2_Pic
  71.  
  72.   -- same as rBESIDE, but with absolute coordinates.
  73. rBESIDE2:: [Movie] -> Movie
  74. rBESIDE2 = reduce beside2
  75.  
  76.   -- puts one Movie on top of the other Movie
  77. over:: Movie -> Movie -> Movie
  78. over = promote2 over_Pic
  79.  
  80.   -- takes a list of Movies, and puts the n-th on top of the first
  81.   -- through 9n-1)th.
  82. rOVER:: [Movie] -> Movie
  83. rOVER = reduce over
  84.  
  85.   -- just overlays the two Movies by appending the Pics.
  86. overlay:: Movie -> Movie -> Movie
  87. overlay = promote2 overlay_Pic
  88.  
  89.   -- overlays a list of Movies by appending the Pics
  90. rOVERLAY:: [Movie] -> Movie
  91. rOVERLAY = reduce overlay
  92.  
  93.   -- promote3 takes a function that takes two items and a Pic and 
  94.   -- returns a Pic, and then applies it to two input lists and a Movie,
  95.   -- producing a new Movie.
  96. promote3:: (a->b->Pic->Pic) -> [a] -> [b] -> Movie -> Movie
  97. promote3 f ps qs rs = [f p q r | (p,q,r) <- zip3 ps qs rs]
  98.  
  99.   -- pUT takes a list of Vectors, and puts each Pic of the first Movie
  100.   -- in the location of the corresponding vector, on top  of the Pic of
  101.   -- the second Movie, and returns that list as a new Movie.
  102. pUT:: [Vec] -> Movie -> Movie -> Movie
  103. pUT = promote3 put_Pic
  104.  
  105.   -- uncurry takes a function that takes two elements and a list of
  106.   -- two elements and applies the function to them.
  107. uncurry:: (a->a->b) -> [a] -> b
  108. uncurry f [a,b] = f a b
  109.  
  110.   -- curry takes a function that takes a list, and two elements, and
  111.   -- then applies the function to the elements in a list.
  112. curry:: ([a]->b) -> a -> a -> b
  113. curry f a b = f [a,b]
  114.  
  115.